package com.atmc.controller;

import com.atmc.bean.Advice;
import com.atmc.mapper.AdviceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class AdviceController {
    @Autowired
    AdviceMapper adviceMapper;
    //去查询所以的用户建议 返回到页面
    @RequestMapping("/toaddadvice")
    public String toaddadvice(Model model){
        List<Advice> list = adviceMapper.selectAll();
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        String name = authentication.getName();
        model.addAttribute("name",name);
        model.addAttribute("msg",list);
        return "html/message";
    }
    //去提交用户建议到数据库
    @RequestMapping("/toaddcontent")
    public String toaddcontent(@RequestParam("content")String content, Model model){

        Advice advice=new Advice(null,content,null,null,null);
        adviceMapper.insertOne(advice);
        List<Advice> list = adviceMapper.selectAll();
        model.addAttribute("msg",list);
        return "html/message";
    }


}
